package com.hup.minicontroller.common.thread.component;

import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 二次处理提交失败时的异常信息
 */
public class SimpleRejectedHandler implements RejectedExecutionHandler {

    private final String executorDesc;

    public SimpleRejectedHandler(String executorDesc) {
        this.executorDesc = executorDesc;
    }

    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        if (executor.isShutdown()) throw new RejectedExecutionException("[" + executorDesc + "]执行器已被停止");
        throw new RejectedExecutionException("[" + executorDesc + "]异步任务数量已达到最大值");
    }

}